'''
Created on Apr 5, 2016

@author: JimmyMo
'''
from dispatchtarget_rabbitmq import DispatchTarget_RabbitMQ
from dispatchmethod_timer import DispatchMethod_Timer
import threading

class MessageBuilderLogPumper(object):
    def __init__(self, config_reader):
        self.config_reader = config_reader
    
    def build(self):
        return "nothing..."
    
class DispatcherLogPumper(threading.Thread):
    def __init__(self, config_reader):
        super(DispatcherLogPumper, self).__init__()
        self.config_reader = config_reader
    def run(self):
        self.dispatch()
    def dispatch(self):
        interval = int(self.config_reader.items["LogPumper"]["Interval"])
        queue_name = self.config_reader.items["LogPumper"]["QueueName"]
        routing_key = self.config_reader.items["LogPumper"]["RoutingKey"]
        rabbitmq_host = self.config_reader.items["General"]["RabbitMQHost"]
        
        target = DispatchTarget_RabbitMQ(host=rabbitmq_host, queue_name=queue_name, routing_key=routing_key, message_builder=MessageBuilderLogPumper(self.config_reader))
        method = DispatchMethod_Timer(interval)
        
        method.set_method_target(target)
        method.dispatch()
    
#     @classmethod
#     def get_dispatch_method(cls):
#         m = DispatchMethod_Timer()
#         return m
#     
#     @classmethod
#     def get_dispatch_target(cls):
#         t = DispatchTarget_RabbitMQ(queue_name="logpumper_q", routing_key="logpumper_q")
#         return t
